package com.lepu.app.fun.chat.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.core.AsyncRequest;
import com.core.lib.utils.main.AppManager;
import com.lepu.app.fun.chat.bean.BeanDoctorMy;
import com.lepu.app.fun.chat.bean.BeanDoctorMyDetail;
import com.lepu.app.fun.chat.business.DoctorManager;
import com.lepu.app.fun.chat.util.ChatUtil;
import com.lepu.app.fun.chat.util.Constants;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;
import com.lepu.pasm.R;

public class DoctorAddActivity extends BaseFragmentActivity implements
		OnTopbarNewLeftLayoutListener,AsyncRequest {

	public static final String REQUEST_DATA = "request_data";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chat_doctor_add_activity);

		init();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	/**
	 * 添加页面动画，需要重写这个方法，
	 */
	@Override
	public void onBackPressed() {
		finish(true);
	}
	
	@Override
	public void onTopbarLeftLayoutSelected() {
		finish(true);
	}


	/**
	 * 初始化方法
	 */
	private void init() {
		// topbar
		CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
		topbar.setTopbarTitle("添加医生");
		topbar.setonTopbarNewLeftLayoutListener(this);
	}
	
	public void viewClick(View v)
	{
		int rid = v.getId();
		switch (rid) {
		case R.id.sendButton:
			
			EditText userEditText = (EditText) findViewById(R.id.userEditText);
			String userContent = userEditText.getText().toString().trim();
			
			if(TextUtils.isEmpty(userContent))
			{
				return;
			}
			
			showProgressDialog();
			DoctorManager.getInstance().requestDoctorSendPhone(this, userContent);
			break;

		default:
			break;
		}
	}

	@Override
	public void RequestComplete(Object object, Object data) {
		if (object.equals(REQUEST_DATA)) {
			hideProgressDialog();

			//发送通知
			BeanDoctorMyDetail item = BeanDoctorMyDetail.parseDetailInfo((String) data);
			if(item != null)
			{
				ChatUtil.sendChatNotice(item.DoctorID);
			}
			
			finish(true);
			DoctorMyActivity instance = (DoctorMyActivity) AppManager.getAppManager().getActivity(DoctorMyActivity.class);
			if(instance != null)
			{
				instance.refreshData();
			}
		} 
	}

	@Override
	public void RequestError(Object object, int errorId, String data) {
		if (object.equals(REQUEST_DATA)) {
			hideProgressDialog();
		} 
	}

}
